package com.passioneffect.collection {

	/**
	 * @author Passion Effect
	 */
	public class ListItem {
		public var previous : ListItem;
		public var next : ListItem;
		private var data:*;
		
		public function ListItem(data:*) {
			this.data=data;
		}
		
		public function getData():*{
			return data;
		}
		
		public function insertFront(item:ListItem):ListItem{
			var front:ListItem=previous;
			if(front){
				front.next=item;
				item.previous=front;
			}
			item.next=this;
			this.previous=item;
			return item;
		}
		
		public function insertBehind(item:ListItem):ListItem{
			
			var behind:ListItem=next;
			if(behind){
				item.next=behind;
				behind.previous=item;
			}
			next=item;
			item.previous=this;
			return item;
		}
		
		public function remove():*{
			var p:ListItem=this.previous;
			var n:ListItem=this.next;
			
			if(p)p.next = n;
			if(n)n.previous=p;
			
			this.next=null;
			this.previous=null;
			
			return data;
		}

		public function toString():String{
			return "data:"+data;
		}
	}
}
